package com.copa.module.goods.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.copa.annotation.Log;
import com.copa.domain.ResponseDto;
import com.copa.module.goods.domain.dto.CategoryDto;
import com.copa.module.goods.domain.vo.CategoryAddVo;
import com.copa.module.goods.domain.vo.CategoryListVo;
import com.copa.module.goods.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author copa
 * @createDate 2021-01-07 16:50
 * @function
 */
@RestController
@Api(tags = {"类目接口"})
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @Log("添加类目")
    @ApiOperation(value = "添加类目")
    @PostMapping("/category/add")
    public ResponseDto<CategoryDto> add(@RequestBody CategoryAddVo categoryAddVo) {
        return categoryService.add(categoryAddVo);
    }

    @ApiOperation(value = "查看类目")
    @GetMapping("/category/list")
    public ResponseDto<List<CategoryDto>> list() {
        return categoryService.list();
    }

    @ApiOperation(value = "查看分页类目")
    @PostMapping("/category/listByPage")
    public ResponseDto<IPage<CategoryDto>> page(@RequestBody CategoryListVo categoryListVo) {
        return categoryService.page(categoryListVo);
    }
}
